package com.ywm.servicebase.config.handle;


import com.ywm.commonUtil.R;
import com.ywm.servicebase.config.util.ExceptionUtil;
import jdk.nashorn.internal.runtime.ErrorManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice//全局异常处理
@Slf4j
public class GlobalExceptionHandler {
    //所有的异常都会进入这个方法
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public R error(Exception e){
        ErrorManager log = new ErrorManager();
        log.error(e.getMessage());
        log.error(ExceptionUtil.getMessage(e));
        e.printStackTrace();
        return R.error().message("发生了错误");
    }

    //特点异常
    @ExceptionHandler(ClassNotFoundException.class)
    @ResponseBody
    public R error2(Exception e){
        e.printStackTrace();
        return R.error().message("发生了找不到类异常");
    }
}